<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>课程数据列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" >
    <script th:src="@{/layui/layui.js}" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<br>
<form class="layui-form" action="" id="searchform">
    <div class="layui-form-item">
        <label class="layui-form-label">name</label>
        <div class="layui-input-inline">
            <input type="text" name="name" id="name" placeholder="请输入书籍名称" autocomplete="off" class="layui-input">
        </div>

        <div class="site-demo-button" id="top_options" style="margin-bottom: 0;margin-right: 20px" align="right" >
            <button class="layui-btn layui-btn-sm" type="button" onclick="doSearch();">Search</button>
            <button type="reset" class="layui-btn layui-btn-sm" >Rest</button>
        </div>
    </div>
</form>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    </div>
</script>

<script type="text/html" id="imgtmp">
    <img src="{{ d.img_url}}">
</script>
<style type="text/css">
    .layui-table-cell{
        height:auto!important;
        white-space:normal;
    }
</style>

<script>
    var table,$;
    layui.use('table', function(){
        table = layui.table;
        var layer = layui.layer;
        $ = layui.jquery;
        table.render({
            elem: '#test'
            ,url:'/coursebook/listJson'
            ,toolbar: '#toolbarDemo'
            ,title: '书籍数据表'
            ,totalRow: true
            ,cols: [
                [
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'id', title:'id值', sort: true}
                    ,{field:'name', title:'书籍名称'}
                    ,{field:'intro', title:'简介'}
                    //,{field:'pic', title:'图片'}
                    ,{field:'pic', title:'图片',width: 320, align: 'center',templet:"#imgtmp"}
                    ,{field:'url', title:'阅读'}
                ]
            ]
            ,page: true
            ,limit:1
            ,limits:[1,6,7,8,9]
            ,id:'bookReload'
        });

        //工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                    break;
                case 'add':
                    layer.msg("暂时无权操作!");
                    break;
            };
        });

    });

    function doSearch() {
        var name = $('#name').val();

        table.reload('bookReload',{
            where:{
                name:name
            }
        });
    }

</script>
</body>
</html>